package user;

import dao.EmployeeDaoFile;
import dao.EmployeeDaoList;
import dao.EmployeeDatabaseDao;
import domain.Employee;
import utils.DateAndString;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/**
 * @version 1.0
 * @autho 3505
 * @date 2018/6/2
 */
public class User {
    //此类负责输入信息形成Employee对象
    private int kind;
    private List<Employee> list = new ArrayList();
    public void view(){
        System.out.println("--------------员工管理系统--------------");
        System.out.println("1.添加员工");
        System.out.println("2.修改员工");
        System.out.println("3.删除员工");
        System.out.println("4.查找一个员工");
        System.out.println("5.查找所有员工");
    }
    public User(int kind) throws Exception {
        this.kind = kind;
        if (kind == 1) {
            EmployeeDaoList employeeDaoList = new EmployeeDaoList();
            Scanner scanner = new Scanner(System.in);
            int flag = 0;
            while (true) {
                Employee employee = new Employee();
                String name = null;
                view();
                int choice = scanner.nextInt();
                //吸收回车
                scanner.nextLine();
                switch (choice) {
                    case 1:
                        DateAndString dateAndString = new DateAndString();
                        System.out.println("请输入员工ID");
                        int employeeID = Integer.valueOf(scanner.nextLine());
                        System.out.println("请输入员工姓名");
                        String employeeName = scanner.nextLine();
                        System.out.println("请输入性别");
                        String sex = scanner.nextLine();
                        System.out.println("请输入出生日期");
                        String birthDate = scanner.nextLine();
                        Date date1 = dateAndString.stringToDate(birthDate);
                        System.out.println("请输入雇佣日期");
                        String hirDate = scanner.nextLine();
                        Date date2 = dateAndString.stringToDate(hirDate);
                        System.out.println("请输入工资");
                        Float salary = Float.valueOf(scanner.nextLine());
                        System.out.println("请输入部门ID");
                        int departmentID = Integer.valueOf(scanner.nextLine());
                        employee = new Employee(employeeID, employeeName, sex, date1, date2, salary, departmentID);
                        System.out.println(employeeDaoList.add(employee));
                        break;
                    case 2:
                        System.out.println("请输入姓名");
                        name = scanner.nextLine();
                        System.out.println(employeeDaoList.searchOne(name));
                        System.out.println("请输入工资");
                        String salary1 = scanner.nextLine();
                        employee.setEmployeeName(name);
                        employee.setSalary(Float.valueOf(salary1));
                        System.out.println(employeeDaoList.modify(employee));
                        break;
                    case 3:
                        System.out.println("请输入姓名");
                        name = scanner.nextLine();
                        System.out.println(employeeDaoList.delete(name));
                        break;
                    case 4:
                        System.out.println("请输入姓名");
                        name = scanner.nextLine();
                        employeeDaoList.searchOne(name);
                        break;
                    case 5:
                        System.out.println(employeeDaoList.searchAll());
                        break;
                    default:
                        System.out.println("您输入有误，请重新输入");
                }
            }
        }else if (kind == 2) {
            EmployeeDaoFile employeeDaoFile = new EmployeeDaoFile();
            Scanner scanner=new Scanner(System.in);
            int choice=0;
            list=employeeDaoFile.readFile();

            while (true){
                Employee employee=new Employee();
                String name=null;
                view();
                choice=scanner.nextInt();
                //吸收回车
                scanner.nextLine();
                switch (choice){
                    case 1:
                        DateAndString dateAndString=new DateAndString();
                        System.out.println("请输入员工ID");
                        int employeeID=Integer.valueOf(scanner.nextLine());
                        System.out.println("请输入员工姓名");
                        String employeeName=scanner.nextLine();
                        System.out.println("请输入性别");
                        String sex=scanner.nextLine();
                        System.out.println("请输入出生日期");
                        String birthDate=scanner.nextLine();
                        Date date1=dateAndString.stringToDate(birthDate);
                        System.out.println("请输入雇佣日期");
                        String hirDate=scanner.nextLine();
                        Date date2=dateAndString.stringToDate(hirDate);
                        System.out.println("请输入工资");
                        Float salary=Float.valueOf(scanner.nextLine());
                        System.out.println("请输入部门ID");
                        int departmentID=Integer.valueOf(scanner.nextLine());
                        employee=new Employee(employeeID,employeeName,sex,date1,date2,salary,departmentID);
                        employeeDaoFile.add(employee);
                        break;
                    case 2:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        employeeDaoFile.searchOne(name);
                        System.out.println("请输入工资");
                        String salary1=scanner.nextLine();
                        employee.setEmployeeName(name);
                        employee.setSalary(Float.valueOf(salary1));
                        System.out.println(employeeDaoFile.modify(employee));
                        break;
                    case 3:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        System.out.println(employeeDaoFile.delete(name));
                        break;
                    case 4:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        employeeDaoFile.searchOne(name);
                        break;
                    case 5:
                        System.out.println(employeeDaoFile.searchAll());
                        break;
                    default:
                        System.out.println("您输入有误，请重新输入");
                }


            }

        } else if (kind == 3) {
            EmployeeDatabaseDao employeeDatabaseDao = new EmployeeDatabaseDao();
            Scanner scanner=new Scanner(System.in);
            int choice=0;
            while (true){
                Employee employee=new Employee();
                String name=null;
                view();
                choice=scanner.nextInt();
                //吸收回车
                scanner.nextLine();
                switch (choice){
                    case 1:
                        DateAndString dateAndString=new DateAndString();
                        System.out.println("请输入员工ID");
                        int employeeID=Integer.valueOf(scanner.nextLine());
                        System.out.println("请输入员工姓名");
                        String employeeName=scanner.nextLine();
                        System.out.println("请输入性别");
                        String sex=scanner.nextLine();
                        System.out.println("请输入出生日期");
                        String birthDate=scanner.nextLine();
                        Date date1=dateAndString.stringToDate(birthDate);
                        System.out.println("请输入雇佣日期");
                        String hirDate=scanner.nextLine();
                        Date date2=dateAndString.stringToDate(hirDate);
                        System.out.println("请输入工资");
                        Float salary=Float.valueOf(scanner.nextLine());
                        System.out.println("请输入部门ID");
                        int departmentID=Integer.valueOf(scanner.nextLine());
                        employee=new Employee(employeeID,employeeName,sex,date1,date2,salary,departmentID);
                        System.out.println(employeeDatabaseDao.add(employee));
                        break;
                    case 2:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        employeeDatabaseDao.searchOne(name);
                        System.out.println("请输入工资");
                        String salary1=scanner.nextLine();
                        employee.setEmployeeName(name);
                        employee.setSalary(Float.valueOf(salary1));
                        System.out.println(employeeDatabaseDao.modify(employee));
                        break;
                    case 3:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        System.out.println(employeeDatabaseDao.delete(name));
                        break;
                    case 4:
                        System.out.println("请输入姓名");
                        name=scanner.nextLine();
                        employeeDatabaseDao.searchOne(name);
                        break;
                    case 5:
                        System.out.println(employeeDatabaseDao.searchAll());
                        break;
                    default:
                        System.out.println("您输入有误，请重新输入");
                }


            }
        }
    }
    }

